﻿/*
 *  PassBag is multi-platform software that securely manage/store passwords
 *  Copyright (C) <2009>  <Hugo Rodrigues PEREIRA>
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *	
 *  You can find a copy of the GPLv3 at project <root directory>/gpl.txt
 *
 */

using System;
using PassBag.Logic;
using PassBag.Utils;

namespace PassBag.Presentation.Logic {
    /// <summary>
    /// Helper class to create <see cref="PasswordObject"/> instance
    /// </summary>
    public sealed class PasswordItem {
        private const int MIN_STRING_LENGTH = 5;
        private const int MAX_STRING_LENGTH = 10;

        /// <summary>
        /// Gets the password object from password string.
        /// </summary>
        /// <param name="password">The password object.</param>
        /// <returns>The <see cref="PasswordObject"/></returns>
        public static PasswordObject GetPasswordObjectFromPassword (string password) {
            PasswordObject passwordObject = new PasswordObject (Guid.NewGuid ());

            passwordObject.Password = password;
            passwordObject.Information = Randomizer.GetRandomString (Randomizer.GetRandomNumber (MIN_STRING_LENGTH, MAX_STRING_LENGTH), false);
            passwordObject.Title = Randomizer.GetRandomString (Randomizer.GetRandomNumber (MIN_STRING_LENGTH, MAX_STRING_LENGTH), false);
            passwordObject.UserName = Randomizer.GetRandomString (Randomizer.GetRandomNumber (MIN_STRING_LENGTH, MAX_STRING_LENGTH), false);
            passwordObject.Url = Randomizer.GetRandomString (Randomizer.GetRandomNumber (MIN_STRING_LENGTH, MAX_STRING_LENGTH), false);
            passwordObject.Comment = Randomizer.GetRandomString (Randomizer.GetRandomNumber (MIN_STRING_LENGTH, MAX_STRING_LENGTH), false);
            passwordObject.LastModified = DateTime.Parse (Randomizer.GetRandomDateTime ().ToString ());

            return passwordObject;
        }

        /// <summary>
        /// Gets the password string from password object.
        /// </summary>
        /// <param name="passwordObject">The <see cref="PasswordObject"/>.</param>
        /// <returns>The password as string</returns>
        public static string GetPasswordStringFromPasswordObject (PasswordObject passwordObject) {
            return passwordObject.Password;
        }
    }
}
